/**
 * Copyright ©2016-2022 tianyu education Corporation, All Rights Reserved
 * http://www.whty.com.cn/
 */
package profile.hujia.shiro.study.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import profile.hujia.shiro.study.dao.UserRepository;
import profile.hujia.shiro.study.model.UserDO;
import profile.hujia.shiro.study.model.UserStatusEnum;
import profile.hujia.shiro.study.service.utils.EncryptionService;

import java.util.Date;

/**
 * class info
 *
 * @author hujia
 * @date 2019-12-09 16:20
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserRepository userRepository;

    @Autowired
    private EncryptionService encryptionService;

    @Override
    public UserDO insertUser(UserDO userDO) {
        userDO.setSalt(encryptionService.getSalt());
        userDO.setPassword(encryptionService.encryption(userDO.getUserName() + userDO.getSalt(), userDO.getPassword()));
        userDO.setStatus(UserStatusEnum.ACTIVED);
        userDO.setGmtCreate(new Date());
        return userRepository.save(userDO);
    }

    @Override
    public UserDO getUser(String userName) {
        return userRepository.findByUserName(userName);
    }
}